<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>商户绑定</title>
		<link rel="stylesheet" href="../css/mui.min.css"/>
		<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/layer/layer.js"></script>
		<link rel="stylesheet" href="../js/layer/skin/layer.css" id="layuicss-skinlayercss">
		<style>
			body{font-family:"微软雅黑"; background: #DEDEDE;}
			.mui-card{border: none;}
			.M-box3{margin: 1em auto;}
			.M-box3 span:first-child{display: block; margin-left: 18%;}
			.M-box3 a:first-child{margin-left: 5%;}
		</style>
	</head>
	<body>
		<div class="mui-content" style="background: #DEDEDE; margin-top: 5px;">
			<div class="mui-card" style="margin-bottom: 5px;">
				<ul>
					<li>		
						<div class="title" style="color:orange;">
							请先绑定商户信息，再查询交易！
						</div>
					</li>
				</ul>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-collapse">
						<form class="mui-input-group">
							<div class="mui-input-row">
								<label>商户号</label>
								<input type="text" class="mui-input-clear" id="mch_id" placeholder="请输入商户号">
							</div>
							<div class="mui-input-row">
								<label>商户名</label>
								<input type="text" class="mui-input-clear" id="mch_name" placeholder="请输入商户名">
							</div>
							<div class="mui-input-row">
								<label>手机号</label>
								<input type="text" class="mui-input-clear" id="phone" placeholder="请输入手机号">
							</div>
							<div class="mui-button-row">
								<button class="mui-btn mui-btn-primary" type="button" id="bind_submit">绑&nbsp;&nbsp;&nbsp;&nbsp;定</button>
							</div>
						</form>
					</li>
				</ul>
			</div>
		</div>
	</body>
	
	<script>
		var openID;
		$(function(){
			openID = GetQueryString('openID');
			$(document).on('click','#bind_submit',function(){
				$.ajax({
					url : '../agent/bind',
					type : 'POST',
					data : {
						'openID' : openID,
						'mch_id' : $('#mch_id').val(),
						'mch_name' : $('#mch_name').val(),
						'phone' : $('#phone').val()
					},
					success : function(res){
						if(res == 'success'){
							layer.confirm('绑定成功！', {
							  btn: ['确定', '取消'] 
							  ,btn2: function(index, layero){
								  layer.close(index);
							  }
							}, function(index, layero){
								window.location = "search.html?openID=" + openID;
							});
						}else if(res == 'same'){
							layer.msg("该商户号已经绑定过！");
						}else{
							layer.msg(res);
						}
					},
					error : function(){
						layer.msg('请求错误，请稍后再试');
					}
				})
			})
		})
		
		/* 获取url后的字符串 */
	    function GetQueryString(name) {
	        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	        var r = window.location.search.substr(1).match(reg);
	        if (r != null) {
	            return (r[2]);
	        }
	        return null;
	    }
	</script>
</html>
